$().ready(function() {
	validateRule();
});

$.validator.setDefaults({
	submitHandler : function() {
		update();
	}
});

var uploadAuthority1 = $("#uploadAuthority1").val();
var downloadAuthority1 = $("#downloadAuthority1").val();
if(uploadAuthority1 != "" && uploadAuthority1 == 0){
	$("#uploadAuthority").attr("class","switchOn")
}else {
	$("#uploadAuthority").attr("class","switchOn switchOff")
}
if(uploadAuthority1 != "" && downloadAuthority1 == 0){
	$("#downloadAuthority").attr("class","switchOn")
}else {
	$("#downloadAuthority").attr("class","switchOn switchOff")
}

var uploadAuthority = 1;
var downloadAuthority = 1;
if(uploadAuthority1 != "") {
	uploadAuthority = uploadAuthority1;
	downloadAuthority = downloadAuthority1;
}
$(document).on('click','.switchOn',function(){
	$(this).toggleClass('switchOff');
	var switchOn=$(this).attr("class")
	var idShow = $(this).attr("id");
	if(switchOn.indexOf("switchOff") == -1) {
		//开
		if(idShow == "uploadAuthority") {
			uploadAuthority = 0;
		}else if(idShow == "downloadAuthority") {
			downloadAuthority = 0;
		}
	}else {
		//关
		if(idShow == "uploadAuthority") {
			uploadAuthority = 1;
		}else if(idShow == "downloadAuthority") {
			downloadAuthority = 1;
		}
	}
});

function update() {
	$.ajax({
		cache : true,
		type : "POST",
		url : "/system/aothority/update",
		data : {
			"id":$("#id").val(),
			"uploadAuthority":uploadAuthority,
			"downloadAuthority":downloadAuthority
		},
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			name : {
				required : true
			}
		},
		messages : {
			name : {
				required : icon + "请输入名字"
			}
		}
	})
}